package com.epfresh.supplier.activity.standingbook;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.aigestudio.wheelpicker.core.AbstractWheelPicker;
import com.aigestudio.wheelpicker.widget.curved.WheelDatePicker;
import com.epfresh.supplier.R;

/**
 * Created by shenjie on 2017/9/22.
 */

public class CancelDebtPopupWindow extends PopupWindow implements View.OnClickListener{
    private Context context;
    private DatePickerPopupWindow.DatePickerListener listener;
    private TextView cancel,ok;
    private WheelDatePicker datePicker;
    private RelativeLayout cc;
    private String dataStr;
    public  CancelDebtPopupWindow(Context context){
        this.context=context;
        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setBackgroundDrawable(new ColorDrawable(0x00000000));
        setAnimationStyle(R.style.popwin_bottom_style);
        initView();
    }

    private void initView(){
        View view= LayoutInflater.from(context).inflate(R.layout.datepicker_window,null);
        setContentView(view);
        cc= (RelativeLayout) view.findViewById(R.id.head);
        cc.setOnClickListener(this);
        cancel= (TextView) view.findViewById(R.id.tv_cancel);
        cancel.setOnClickListener(this);
        ok= (TextView) view.findViewById(R.id.tv_ok);
        ok.setOnClickListener(this);
        datePicker= (WheelDatePicker) view.findViewById(R.id.datepicker);
        datePicker.setOnWheelChangeListener(new AbstractWheelPicker.OnWheelChangeListener() {
            @Override
            public void onWheelScrolling(float deltaX, float deltaY) {

            }

            @Override
            public void onWheelSelected(int index, String data) {
                dataStr=data;
            }

            @Override
            public void onWheelScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.head:
            case R.id.tv_cancel:
                dismiss();
                break;
            case R.id.tv_ok:
                dismiss();
                if(listener!=null){
                    listener.select(dataStr);
                }
                break;
        }
    }

    public  interface DatePickerListener{
        public void select(String date);
    }

    public DatePickerPopupWindow.DatePickerListener getListener() {
        return listener;
    }

    public void setListener(DatePickerPopupWindow.DatePickerListener listener) {
        this.listener = listener;
    }
}
